<template>
  <div>
    <div
      id="myEcharts"
      :style="{ height: `${echartsH}px`, width: `${echartsW}px` }"
    ></div>
  </div>
</template>

<script>
import * as Echarts from "echarts";
import { computed } from "vue";

export default {
  data() {
    return {
      echartsW: (window.innerWidth - 400) / 2,
      echartsH: window.innerHeight / 2 + 0,
      // echartsW: (document.body.clientWidth - 400) / 2,
      // echartsH: document.body.clientHeight / 2 + 100,
    };
  },
  methods: {
    drawLine() {
      var myChart = Echarts.init(document.getElementById("myEcharts"));
      var option = {
        title: {
          text: "World Population",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        legend: {},
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
        },
        yAxis: {
          type: "category",
          data: ["Brazil", "Indonesia", "USA", "India", "China", "World"],
        },
        series: [
          {
            name: "2011",
            type: "bar",
            data: [18203, 23489, 29034, 104970, 131744, 630230],
          },
          {
            name: "2012",
            type: "bar",
            data: [19325, 23438, 31000, 121594, 134141, 681807],
          },
        ],
      };
      myChart.setOption(option);
    },
  },
  mounted() {
    this.drawLine();
  },
};
</script>

<style lang="less" scoped>
#myEcharts {
  margin-top: 40px;
  margin-left: 50px;
  //   width: 500px;
  //   height: 400px;
  background-color: rgb(255, 255, 255);
}
</style>